<template>
  <div class="aui-card-list">
    <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}"
      @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item label="填报主题">
          <el-input v-model="dataForm.title" placeholder="填报主题" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="填报单位">
          <el-input v-model="dataForm.btypeName" placeholder="填报单位" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="周期">
          <el-input v-model="dataForm.fillCycle" placeholder="周期" clearable></el-input>
        </el-form-item>
      </el-col>
    </uni-list-query-card>
    <el-card shadow="never" class="aui-card-list-body">
      <vxe-toolbar :setting="{immediate:true}">
        <template v-slot:buttons>
          <vxe-tooltip content="手动生成当前日期的任务，也可用job定时任务实现！" enterable>
            <el-button type="primary" @click="check()">{{ '任务生成' }}</el-button>
          </vxe-tooltip>
          <el-button v-if="$hasPermission('udf:udfFillingLog:delete')" type="danger" @click="deleteHandle()">
            {{ $t('deleteBatch') }}</el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <div class="aui-card-list-body-table">
        <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize
          @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex"
          :data="dataList" max-height="auto">
          <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
          <vxe-table-column field="title" title="填报主题">
          </vxe-table-column>
          <vxe-table-column field="btypeName" title="填报单位">
          </vxe-table-column>
          <vxe-table-column field="fillTitle" title="填报标题">
          </vxe-table-column>
          <vxe-table-column field="cycleType" title="周期" width="80" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.cycleType == 'year'" size="small" type="info">年报</el-tag>
              <el-tag v-if="scope.row.cycleType == 'year_half'" size="small" type="info">半年报</el-tag>
              <el-tag v-if="scope.row.cycleType == 'quarterly'" size="small" type="success">季报</el-tag>
              <el-tag v-if="scope.row.cycleType == 'month'" size="small" type="warning">月报</el-tag>
              <el-tag v-if="scope.row.cycleType == 'week'" size="small" type="info">周报</el-tag>
              <el-tag v-if="scope.row.cycleType == 'day'" size="small" type="danger">日报</el-tag>
            </template>
          </vxe-table-column>
          <vxe-table-column field="fillYear" title="填报年度" width="80">
          </vxe-table-column>
          <vxe-table-column field="fillCycle" title="填报周期">
          </vxe-table-column>
          <vxe-table-column field="updateDate" title="最后更新时间">
          </vxe-table-column>
          <vxe-table-column title="handle" width="150" fixed="right" align="center">
            <template slot-scope="scope">
              <!-- <el-button v-if="$hasPermission('udf:udfFillingLog:update')" type="text" size="small" icon="el-icon-edit"
              @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button> -->
              <el-button v-if="$hasPermission('udf:udfFillingLog:delete')" type="text" size="small"
                icon="el-icon-delete" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
              <!-- 此处只判断状态，如需限制时间请自行添加, scope.row 里面的 fillBdate fillEdate 是建议的填报时间-->
              <el-button v-if="scope.row.status===1" type="text" size="small" icon="el-icon-truck">{{ '已报' }}
              </el-button>
              <el-button v-else type="text" size="small" icon="el-icon-truck" @click="fill(scope.row)">{{
              '填报' }}</el-button>
            </template>
          </vxe-table-column>
        </vxe-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
          layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
        </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </el-card>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './udfFillingLog-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/udf/udfFillingLog/selectPageMonitor',
        getDataListIsPage: true,
        deleteURL: '/udf/udfFillingLog',
        deleteIsBatch: true,
        exportURL: '/udf/udfFillingLog/export'
      },
      dataForm: {
        title: '',
        btypeName: '',
        fillCycle: '',
        status: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    check () {
      this.$http.post('/udf/udfFillingTask/check', {}).then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        this.$message.success(res.msg)
      })
    },
    fill (row) {
      let id = row.id
      // 打开路由
      var router = {
        name: 'udf-udfFillingLog-fill',
        id: id,
        menuId: this.$route.meta.menuId,
        oldName: 'udf-udfFillingLog',
        path: row.url,
        title: '填报' + (row.topicName ? ' - ' + row.topicName : '')
      }
      var params = {
        timestamp: this.$xeutils.timestamp(),
        logId: id
      }
      this.$options.methods.openNewTab(this.$router, router, params)
    },
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
